package com.wuxb.myDisruptor;

import com.lmax.disruptor.RingBuffer;
import com.lmax.disruptor.YieldingWaitStrategy;
import com.lmax.disruptor.dsl.Disruptor;
import com.lmax.disruptor.dsl.ProducerType;

import java.nio.ByteBuffer;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class LongEventMain {
    public static void main(String[] args) {

        ExecutorService threadPool = Executors.newCachedThreadPool();
        LongEventFactory factory = new LongEventFactory();
        int ringBufferSize = 1024*1024;

        Disruptor<LongEvent> disruptor = new Disruptor<LongEvent>(factory, ringBufferSize, threadPool, ProducerType.SINGLE, new YieldingWaitStrategy());

        disruptor.handleEventsWith(new LongEventHandle());

        disruptor.start();

        RingBuffer<LongEvent> ringBuffer = disruptor.getRingBuffer();

        LongEventProduct longEventProduct = new LongEventProduct(ringBuffer);

        ByteBuffer byteBuffer = ByteBuffer.allocate(8);

        for (int i = 0; i <100 ; i++) {
            byteBuffer.putLong(0,i);
            longEventProduct.onData(byteBuffer);
        }

    }
}
